#ifndef __PICASA_H__
#define __PICASA_H__

#include <QVector>
#include <QString>
#include <QMap>
#include <QHttp>
#include <QBuffer>
#include <QDomNode>
#include <QTemporaryFile>
#include <QStringList>
#include <QtCore>
#include <QLinkedList>

typedef QMap<QString, QString> StringMap;
Q_DECLARE_METATYPE(StringMap);

typedef QVector<QString> StringVector;
Q_DECLARE_METATYPE(StringVector);

typedef QVector<int> IntVector;
Q_DECLARE_METATYPE(IntVector);

typedef QMap<int, QBuffer*> BufferList;
Q_DECLARE_METATYPE(BufferList);


class Picasa: public QObject
{
	Q_OBJECT
	public:
		Picasa();
		void Auth(const QString& UserName, const QString& Password);
		void GetExistingAlbums();
		QString BuildPostData(const QMap<QString, QString>& map);
		void ParseAuthResponse(const QString& AuthResponse, QMap<QString, QString>& FilledMap);
		//void GetCaptchaImage(const QString& CaptchaString);
		void PostImageRequest( const QString& AlbumTitle, const QString& FilePath );
		void ThrowError( int ErrorId, const QString& ErrorMessage);
		void ResetBuffer( QBuffer*& buffer );
		void Director( const QString& Directory, const QString& AlbumTitle );
		bool GetAlbumsNames( QIODevice& AlbumsInXml, StringVector& RetVector, QString& ErrorMessage );
		QHttp* http;
		//PostImage postimages;
		
	private slots:
		void readResponseHeader(const QHttpResponseHeader &responseHeader);
		void slGetExistingAlbums(int requestId, bool error);
		void slAuthRequestFinished(int requestId, bool error);
		//void slGotCaptchaImage(int requestId, bool error);
		void slPostImage(int requestId, bool error);
		void slSendProgressPostImage(int done, int total);
		void slAnyRequestFinished( int requestId, bool error);
		
	private:
		QHttpResponseHeader CurrentResponseHeader;
		//QMap<QString, QString> ResponseMap;
		//const QString PICASAHOST;
//		QBuffer AlbumsXml;
		QBuffer* bufferok;
		
		QString UserName;
		QString PassWord;
		QStringList  PicasaSupportedImageTypes;
		QString GoogleAuthValue;
		
		QTemporaryFile TmpFile;

		int httpGetAlbumsId;
		int httpRequestAuthId;
		int httpGetCaptchaId;	
		int httpPostImageId;
		//IntVector httpPostImageVector;
		//BufferMap PostImageResponses;

		void parseEntry(const QDomElement& element, QVector<QString>& AlbumsTitles);
	signals:
		void siAuth( const StringMap& map );
		void siGetExistingAlbums( const StringVector& vector );
		void siPostImage();
		void siThrowError( int ErrorId, const QString& ErrorString );
};

#endif // __PICASA_H__
